package com.eascs.p2p.admin.service.impl;

import javax.inject.Inject;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.p2p.admin.manager.IInvestRecordManager;
import com.eascs.p2p.common.entity.InvestorRecordEntity;
import com.eascs.p2p.common.service.IInvestorRecordService;
import com.eascs.p2p.common.vo.InvestRecordVO;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.p2p.common.vo.TransactionRecordVO;

@Service
public class InvestRecordServiceImpl implements IInvestorRecordService {
	private static Logger logger = LoggerFactory.getLogger(InvestRecordServiceImpl.class);
	@Inject
	IInvestRecordManager investRecordManager;
	
	@Override
	public ModelResult<PageResult<InvestorRecordEntity>> findFontPageInvestRecordEntity(InvestRecordVO vo) {
		ModelResult<PageResult<InvestorRecordEntity>> result=new ModelResult<PageResult<InvestorRecordEntity>>();
		try{
			result.setModel(investRecordManager.findFontPageInvestRecordEntity(vo));
		}catch(Exception e){
			e.printStackTrace();
			result.withError("投资记录分页查询：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<PageResult<InvestorRecordEntity>> findFontPageDealRecordEntity(InvestRecordVO vo) {
		ModelResult<PageResult<InvestorRecordEntity>> result=new ModelResult<PageResult<InvestorRecordEntity>>();
		try{
			result.setModel(investRecordManager.findFontPageDealRecordEntity(vo));
		}catch(Exception e){
			e.printStackTrace();
			result.withError("交易记录分页查询：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<PageResult<Object[]>> findPageInvestRecordEntity(InvestRecordVO vo) {
	
		ModelResult<PageResult<Object[]>> result=new ModelResult<PageResult<Object[]>>();
		try{
			result.setModel(investRecordManager.findPageInvestRecordEntity(vo));
		}catch(Exception e){
			e.printStackTrace();
			result.withError("后台投资记录分页查询：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<InvestRecordVO> findInvestRecordVO(InvestRecordVO vo) {
		
		ModelResult<InvestRecordVO> result=new ModelResult<InvestRecordVO>();
		try{
			result.setModel(investRecordManager.findInvestRecordVO(vo));
		}catch(Exception e){
			e.printStackTrace();
			result.withError("查询总投资金额和总投资笔数：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Integer> getInvestorNum(InvestRecordVO vo) {
	
		ModelResult<Integer> result=new ModelResult<Integer>();
		try{
			result.setModel(investRecordManager.getInvestorNum(vo));
		}catch(Exception e){
			e.printStackTrace();
			result.withError("查询总投资者总数", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<PageResult<TransactionRecordVO>> queryPageInvestRecord(InvestorRecordEntity investRecord,
			int pageSize, int pageIndex,int objectStatus) {
		ModelResult<PageResult<TransactionRecordVO>> result = new ModelResult<>();
		try {
			PageResult<TransactionRecordVO> pageReult = investRecordManager.queryPageInvestRecord(investRecord,objectStatus, pageSize, pageIndex);
			result.withModel(pageReult);
		} catch (Exception e) {
			logger.error("获取投资记录失败, error:{}", e.getMessage());
			result.withError("InvestRecordServiceImpl.queryPageInvestRecord", "获取投资记录");
			e.printStackTrace();
			return result;
		}
		return result;
	}

}
